package com.px.biz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.px.biz.domain.PurchaseOrderDetailDO;
import com.px.biz.service.IPurchaseOrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.px.biz.dao.PurchaseOrderDao;
import com.px.biz.domain.PurchaseOrderDO;
import com.px.biz.service.IPurchaseOrderService;
import org.springframework.transaction.annotation.Transactional;


@Service
public class PurchaseOrderServiceImpl extends ServiceImpl<PurchaseOrderDao,PurchaseOrderDO> implements IPurchaseOrderService {

    @Autowired
    private IPurchaseOrderDetailService purchaseOrderDetailService;

    @Override
    public List<HashMap> listPage(Map params) {
        return this.baseMapper.listPage(params);
    }

    @Override
    @Transactional
    public void bizSave(PurchaseOrderDO po, List<PurchaseOrderDetailDO> pods) {
        this.save(po);
        purchaseOrderDetailService.saveBatch(pods);
    }

    @Override
    @Transactional
    public void bizUpdate(PurchaseOrderDO po, List<PurchaseOrderDetailDO> pods) {
        this.updateById(po);
        purchaseOrderDetailService.remove(
                new LambdaQueryWrapper<PurchaseOrderDetailDO>()
                        .eq(PurchaseOrderDetailDO::getOrderId,po.getId())
        );
        purchaseOrderDetailService.saveBatch(pods);
    }
}
